from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import render, HttpResponse


class MyMiddleware1(MiddlewareMixin):
    def process_request(self, request):
        print('执行了MyMiddleware1里面的process_request方法')
        # return HttpResponse("回去不走了")


    def process_response(self, request, response):
        print('执行了MyMiddleware1里面的process_response方法')
        return response
        # return HttpResponse("中途被我调包喽")

    def process_view(self, request, view_func, view_args, view_kwargs):
        print('执行了MyMiddleware1里面的process_view方法')
        print(request, view_func, view_args, view_kwargs)

    def process_exception(self, request, exception):
        print('执行了MyMiddleware1里面的process_exception方法')
        print(exception)

    def process_template_response(self, request, response):
        print('执行了MyMiddleware1里面的process_template_response方法')
        return response

class MyMiddleware2(MiddlewareMixin):
    def process_request(self, request):
        print('执行了MyMiddleware2里面的process_request方法')

    def process_response(self, request, response):
        print('执行了MyMiddleware2里面的process_response方法')
        return response

    def process_view(self, request, view_func, view_args, view_kwargs):
        print('执行了MyMiddleware2里面的process_view方法')
        print(request, view_func,  view_args, view_kwargs)

    def process_exception(self, request, exception):
        print('执行了MyMiddleware2里面的process_exception方法')

    def process_template_response(self, request, response):
        print('执行了MyMiddleware2里面的process_template_response方法')
        return response